<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

class LoginModel extends JLModelBase {

    /**
     * Funcion que loguea al usuario
     * @Retorna bool
     */
    public function login($user, $pwd) {
        $sql = "SELECT 
                tbl_users.int_id_user,
                tbl_users.var_fullname,
                tbl_users.var_email,
                tbl_users.var_username,
                tbl_users.dat_creation,
                tbl_users.dat_modification,
                tbl_users.int_id_typeuser,
                tbl_users.int_id_section,
                tbl_sections.var_desc_section,
                tbl_typeusers.var_desc_typeuser,
                tbl_states.var_htmldesc
            FROM
                tbl_typeusers
                INNER JOIN tbl_users ON (tbl_typeusers.int_id_typeuser = tbl_users.int_id_typeuser)
                INNER JOIN tbl_states ON (tbl_users.int_id_state = tbl_states.int_id_state)
                INNER JOIN tbl_sections ON (tbl_users.int_id_section = tbl_sections.int_id_section)
            WHERE tbl_users.var_username = ? AND tbl_users.var_pwd = ? AND tbl_users.int_id_state <> 3
            LIMIT 1";

        $sth = $this->getDbh()->prepare($sql);
        $sth->bindParam(1, $user, PDO::PARAM_STR);
        $sth->bindParam(2, $pwd, PDO::PARAM_STR);
        $sth->execute();
        return $sth->fetch(PDO::FETCH_ASSOC);
    }

}